package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;

import com.bumptech.glide.Glide;
import com.hxd.otc.R;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.common.enums.BankType;
import com.hxd.otc.module.my.contract.AddAlipayOrWeiXinContract;
import com.hxd.otc.module.my.model.BankModel;
import com.hxd.otc.module.my.model.UploadImageModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.LogUtils;
import com.hxd.otc.utils.ResourceUtil;

import java.io.File;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by lzy on 2018/6/8 0008.
 * description ${添加支付宝微信}
 */
public class AddAlipayOrWeiXinPresenter extends BasePresenter<AddAlipayOrWeiXinContract.View> implements AddAlipayOrWeiXinContract.Presenter {

    private final BankModel mBankModel;
    private final UploadImageModel mUploadImageModel;
    private BankType mBankType;

    public AddAlipayOrWeiXinPresenter(AddAlipayOrWeiXinContract.View view) {
        super(view);
        mBankModel = BankModel.getInstance();
        mUploadImageModel = UploadImageModel.getInstance();
    }


    @Override
    public void addAliPay(String payNo, String qrcodeId, String country, String realName, String remark) {
        mBankModel.addAlipayOrWinXin(mBankType, payNo, qrcodeId, country, realName, new BaseObserver<Object>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
                mView.addAliPayOrWeiXinSuccess(mBankType, msg);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean>bindAutoDispose());
    }

    @Override
    public void uploadImage(File file) {
        mUploadImageModel.uploadImage(file, new Observer<String>() {

            @Override
            public void onError(Throwable e) {
                mView.uploadImageFail(e.getMessage());
            }

            @Override
            public void onComplete() {
            }

            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onNext(String result) {
                mView.showToast(ResourceUtil.getString(R.string.upload_success));
                mView.uploadImageSuccess(result);

            }
        }, mView.<String>bindAutoDispose());
    }

    @Override
    public void setBankType(BankType bankType) {
        mBankType = bankType;
    }
}
